package eight.test_8_3;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class TestMain3 {
    static class Edge {
        int to;
        boolean visited;
        public Edge(int to) {
            this.to = to;
            this.visited = false;
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int t = 0; t < T; t++) {
            int n = scanner.nextInt();
            int x = scanner.nextInt();
            x--;
            List<List<Edge>> graph = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                graph.add(new ArrayList<>());
            }
            for (int i = 0; i < n; i++) {
                int u = scanner.nextInt() - 1;
                int v = scanner.nextInt() - 1;
                graph.get(u).add(new Edge(v));
                graph.get(v).add(new Edge(u));
            }
            boolean xOnCycle = false;
            boolean[] visited = new boolean[n];
            for (int i = 0; i < n && !xOnCycle; i++) {
                if (!visited[i]) {
                    if (dfs(graph,visited,i,-1)) {
                        xOnCycle = i == x || findCycle(graph,visited,i,-1,x);
                    }
                }
            }
            System.out.println(xOnCycle ? "MiXiaoYou" : "PaiMon");
        }


    }
    private static boolean dfs(List<List<Edge>> graph, boolean[] visited,int node,int parent) {
        visited[node] = true;
        for (Edge edge : graph.get(node)) {
            if (edge.visited || (edge.to == parent) ){
                continue;
            }
            edge.visited = true;
            if(visited[edge.to] || dfs(graph,visited,edge.to,node)) {
                return true;
            }
        }
        return false;
    }
    private static  boolean findCycle(List<List<Edge>> graph, boolean[] visited, int node, int parent,int x) {
        if(node == x) {
            return true;
        }
        for (Edge edge : graph.get(node)) {
            if (edge.visited && edge.to != parent && findCycle(graph,visited,edge.to,node,x)) {
                return true;
            }
        }
        return false;
    }
}
